import mitmproxy.http
import getwebvpnpath,config
from mitmproxy import ctx

class ModifyRequest:


    def request(self, flow: mitmproxy.http.HTTPFlow):
        url = flow.request.pretty_url
        if "stu.edu.cn" not in url:
            flow.request.url = getwebvpnpath.aget(flow.request.pretty_url)
            
        elif "webvpn.stu.edu.cn" in url:
            if "-s." in url and url.startswith("https://webvpn") == False:
                flow.request.url = url.replace("https://","http://",1)
                ctx.log.info(f"修改后的URL: {flow.request.url}")
            twfid = config.gcon("setting","twfid")
            flow.request.cookies.update({"TWFID":twfid})
            #ctx.log.info(f"修改后的Cookies: {flow.request.cookies}")
addons = [
    ModifyRequest()
]

